/*
 * Copyright (c) 2025 EasyAdmin
 * All rights reserved.
 *
 * This file is part of the [EasAdmin] project.
 * Unauthorized copying of this file, via any medium, is strictly prohibited.
 * Proprietary and confidential.
 *
 * Author: EasyAdmin ( 1073602@qq.com )
 * Website: https://www.xhxiao.com
 */
package com.easy.module.system.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.easy.framework.common.validate.Add;
import com.easy.framework.common.validate.Update;
import com.easy.framework.database.entity.LogicDeleteEntity;

import com.easy.framework.poi.annotation.Excel;
import com.easy.framework.poi.annotation.Option;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;

import java.util.Set;

/**
 * 角色管理 实体
 *
 * @author EasyAdmin ( 1073602@qq.com )
 * @date 2025-08-19
 */
@Getter
@Setter
@TableName("sys_role")
public class SysRole extends LogicDeleteEntity {
    private static final long serialVersionUID = 1L;

    /**
     * 角色编号
     */
    @NotNull(message = "角色编号不能为空", groups = {Update.class})
    @Excel(name = "角色编号")
    @TableId(type = IdType.AUTO)
    private Long id;

    /**
     * 角色名称
     */
    @Excel(name = "角色名称")
    @NotBlank(message = "角色名称不能为空", groups = {Add.class, Update.class})
    @Size(min = 0, max = 50, message = "角色名称长度不能超过30个字符", groups = {Add.class, Update.class})
    private String roleName;

    /**
     * 角色标识
     */
    @Excel(name = "角色标识")
    @NotBlank(message = "角色标识字符不能为空", groups = {Add.class, Update.class})
    @Size(min = 0, max = 32, message = "角色标识字符长度不能超过32个字符", groups = {Add.class, Update.class})
    private String roleKey;

    /**
     * 顺序
     */
    @Excel(name = "顺序")
    @NotNull(message = "顺序不能为空", groups = {Add.class, Update.class})
    private Integer sort;

    /**
     * 数据范围（1：全部数据权限 2：自定数据权限 3：本部门数据权限 4：本部门及以下数据权限）
     */
    @Excel(
            name = "数据范围",
            options = {
                    @Option(value = "1", name = "所有数据权限"),
                    @Option(value = "2", name = "自定义数据权限"),
                    @Option(value = "3", name = "本部门数据权限"),
                    @Option(value = "4", name = "本部门及以下数据权限"),
                    @Option(value = "5", name = "仅本人数据权限")
            }
    )
    private String dataScope;

    /**
     * 菜单树选择项是否关联显示
     */
    private Boolean menuCheckStrictly;

    /**
     * 部门树选择项是否关联显示
     */
    private Boolean deptCheckStrictly;

    /**
     * 角色状态（0正常 1停用）
     */
    @Excel(
            name = "角色状态",
            options = {
                    @Option(value = "0", name = "正常"),
                    @Option(value = "1", name = "停用")
            }
    )
    private Integer status;

    /**
     * 备注
     */
    @Excel(name = "备注")
    private String remark;


    /**
     * 用户是否存在此角色标识 默认不存在
     */

    @TableField(exist = false)
    private boolean flag = false;

    /**
     * 菜单组
     */
    @TableField(exist = false)
    private Long[] menuIds;

    /**
     * 部门组（数据权限）
     */
    @TableField(exist = false)
    private Long[] deptIds;

    /**
     * 角色菜单权限
     */
    @TableField(exist = false)
    private Set<String> permissions;

    public boolean isAdmin() {
        return isAdmin(this.id);
    }

    public static boolean isAdmin(Long roleId) {
        return roleId != null && 1L == roleId;
    }

}
